package com.axjy.yycg.service.impl;

import com.axjy.yycg.mapper.RoleMapper;
import com.axjy.yycg.pojo.Role;
import com.axjy.yycg.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * User: ZhangXuanWei
 * Time: 2018/3/20 21:08
 * Description:
 */
@Service("roleService")
@Transactional
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    /**
     * 查询所有角色
     * @return
     */
    @Override
    public List<Role> list() {
        return roleMapper.list();
    }

    /**
     * 添加角色
     * @param role
     */
    @Override
    public void addRole(Role role) {
        roleMapper.addRole(role);
    }

    /**
     * 根据ID批量删除角色
     * @param ids
     */
    @Override
    public void batchDel(Integer[] ids) {
        if(ids!=null&&ids.length>0){
            for(Integer id:ids){
                roleMapper.batchDel(id);
            }
        }
    }

    /**
     * 根据id修改角色状态
     * @param id
     * @param state
     */
    @Override
    public void updateState(Integer id, Integer state) {
        Integer num;
        if(state==1){
            num=state-1;
        }else {
            num=state+1;
        }
        roleMapper.updateState(id,num);
    }

    /**
     * 根据ID修改角色名称
     * @param id
     * @param name
     */
    @Override
    public void updateName(Integer id, String name) {
        roleMapper.updateName(id,name);
    }
}
